JColorchooser
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class sri8
{
public static void main(String args[])
{
JFrame f=new JFrame("rainbow");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton b=new JButton("pick to change background");
ActionListener ac=new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
Color initialBackground=b.getBackground();
Color background=JColorChooser.showDialog(null,"rainbow",initialBackground);
if(background!=null)
{
b.setBackground(background);
}
}
};
b.addActionListener(ac);
f.add(b,BorderLayout.CENTER);
f.setSize(300,300);
f.setVisible(true);
}
}